﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Services;

public partial class adm_vlg_adminSupport : System.Web.UI.Page
{
    CommonPage cm3 = new CommonPage();
    VLGDataContext _db8 = new VLGDataContext();
    //string cateId = "";
    protected void Page_Load(object sender, EventArgs e)
    {

        if (IsPostBack) return;
        //LoadListCategory();
        fillDulieuLenGrid();
    }


    void fillDulieuLenGrid()
    {

        var list = from a in _db8.Supports
                   orderby a.TimeInput descending
                   select a;
        GridView1.DataSource = list;
        GridView1.DataBind();
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {

        fillDulieuLenGrid();
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataBind();
    }
    //protected void GridView1_RowDataBound(Object sender, GridViewRowEventArgs e)
    //{

    //    if (e.Row.RowType == DataControlRowType.DataRow)
    //    {
    //        VLGAccount user = e.Row.DataItem as VLGAccount;
    //        // Display the company name in italics.
    //        //e.Row.Cells[1].Text = "<i>" + e.Row.Cells[1].Text + "</i>";
    //        HyperLink hpAcc = e.Row.FindControl("hpAdminDisableAcc") as HyperLink;
    //        HyperLink hpInbox = e.Row.FindControl("hpAdminDisableInbox") as HyperLink;
    //        if (user != null)
    //        {
    //            //xu ly khoa mo tai khoan
    //            if (user.AdminDisableAcc.HasValue&& user.AdminDisableAcc == true)
    //            {
    //                hpAcc.Text = "Đã khóa";
    //                hpAcc.ToolTip = "Click để mở khóa tài khoản";
    //                hpAcc.NavigateUrl = user.idAcc.ToString();
    //                hpAcc.CssClass = "active_acc";
    //            }
    //            else
    //            {
    //                hpAcc.Text = "Đang hoạt động ";
    //                hpAcc.ToolTip = "Click để khóa tài khoản";
    //                hpAcc.NavigateUrl = user.idAcc.ToString();
    //                hpAcc.CssClass = "active_acc";
    //            }
    //            //xu ly khoa mo inbox
    //            if (user.AdminDisableInbox.HasValue&& user.AdminDisableInbox == true)
    //            {
    //                hpInbox.Text = "Đã khóa";
    //                hpInbox.ToolTip = "Click để mở khóa hộp thư";
    //                hpInbox.NavigateUrl = user.idAcc.ToString();
    //                hpInbox.CssClass = "active_inbox";
    //            }
    //            else
    //            {
    //                hpInbox.Text = "Đang hoạt động ";
    //                hpInbox.ToolTip = "Click để khóa hộp thư";
    //                hpInbox.NavigateUrl = user.idAcc.ToString();
    //                hpInbox.CssClass = "active_inbox";
    //            }
    //        }
    //    }

    //}
    //Cập nhật ẩn hiện trên lưới
    public void chkAnHien_OnCheckedChanged(object sender, EventArgs e)
    {
        CheckBox chkAnHien = (CheckBox)sender;
        GridViewRow row = (GridViewRow)chkAnHien.NamingContainer;
        string cid = chkAnHien.ToolTip;
        bool status = chkAnHien.Checked;
        Category cate = _db8.Categories.SingleOrDefault(x => x.idCategory == int.Parse(cid));
        cate.AnHien = status;
        _db8.SubmitChanges();
        // fillDulieuLenGrid();
    }
    protected void linkAdd_Click(object sender, EventArgs e)
    {
        Response.Redirect(ResolveClientUrl("~/qlcongviec.aspx?op=add"));
    }

    protected void linkEditG_Click(object sender, EventArgs e)
    {

    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="idAcc"></param>
    /// <returns>
    /// 0 : có lỗi
    /// 1 : xóa thành công
    /// </returns>
    /// Van chua kiem tra admin moi duoc thao tac
    [WebMethod]
    public static int AdminDeleteSupport(string idSupport)
    {

        if (!string.IsNullOrEmpty(idSupport))
        {
            try
            {
                VLGDataContext _dataContext = new VLGDataContext();
                CommonPage _comment = new CommonPage();

                var support = (from o in _dataContext.Supports
                           where o.idSupport == Convert.ToInt32(idSupport) //&& _comment.Customer.idGroup.ToLower().Equals("admin")
                           select o).Single();

                _dataContext.Supports.DeleteOnSubmit(support);
                _dataContext.SubmitChanges();
                return 1; 
            }
            catch
            {

                return 0;
            }

        }
        else return 0;
    }
}
